package com.by.service.impl;



import com.by.common.utils.Assert;
import com.by.bean.Customer;
import com.by.common.bean.PageBean;
import com.by.common.crud.BaseServiceImpl;
import com.by.mapper.CustomerMapper;
import com.by.query.CustomerQuery;
import com.by.service.CustomerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

@Service
public class CustomerServiceImpl extends BaseServiceImpl<Customer, CustomerMapper> implements CustomerService {

    @Autowired
    CustomerMapper customerMapper;


    @Override
    public PageBean queryByMap(CustomerQuery query) {
        //分页查询
        PageHelper.startPage(query.getPage(), query.getPageSize());//后面紧跟查询
        List list = customerMapper.queryByMap(query);
        PageInfo info = new PageInfo(list);
        return new PageBean(query.getPage(), query.getPageSize(), info.getTotal(), list);
    }

    @Override
    public int active(int id) {
        int rs=customerMapper.active(id);
        Assert.isZero(rs,"用户激活失败");
        return 1;
    }
    @Override
    public int deactivate(int id) {
        int rs=customerMapper.deactivate(id);
        Assert.isZero(rs,"用户下机失败");
        return 1;
    }

    @Transactional
    @Override
    public int delete(Serializable id) {
        //删除用户
        int rs=customerMapper.delete(id);
        Assert.isZero(rs,"客户删除失败");
        return super.delete(id);
    }

}
